<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>修改昵称</title>
    <!-- 基本框架 -->
    <link rel="stylesheet" href="../../../css/common.css">
    <script src="../../../script/vue.min.js" type="text/javascript"></script>
    <script src="../../../script/frame.js" type="text/javascript"></script>
    <script src="../../../script/baseConfig.js" type="text/javascript"></script>
    <script src="../../../script/utils.js" type="text/javascript"></script>
    <script src="../../../script/common.js" type="text/javascript"></script>
    <style>
        body{background:#FFF;}
        #container{padding:0;}
        #container .nickInput{
          background:#F9F9F9;
          display: block;
          width:100%;
          height:0.9rem;
          line-height:0.4rem;
          padding:0.25rem 0.3rem;
          font-size:0.29rem;
        }
        #container .nickInput::-webkit-input-placeholder {
          color: #d5d5d5;
        }
    </style>
</head>
<body>
    <div id="app" v-cloak>
        <div id="container">
            <input type="text" v-model.trim="nick_name" placeholder="请输入昵称" class="nickInput" />
        </div>
    </div>
    <script type="text/javascript">
        apiready = function() {
            var app = new Vue({
                el:'#app',
                data:{
					iosTest:false,
                    nick_name: '',
                    isFetching: false,
                },
                created(){
                    this.nick_name = api.pageParam.data.nick_name;
                },
                methods:{
                    saveNickName: function(){
                        var _this = this;
                        if(this.isFetching){
                            return false;
                        }
                        if(this.nick_name == ''){
                            $.toast('用户昵称不能为空');
                            return false;
                        }
                        this.isFetching = true;
                        $.ajax({
                            url: '/user/info/change',
                            method: 'post',
                            load: true,
                            data: {
                                user_name: this.nick_name
                            },
                            success: function(res){
                                api.sendEvent({
                                    name: 'updateSettingsPage',
                                });
                                api.sendEvent({
                                    name: 'updateMyIndexPage'
                                });
                                api.closeWin();
                            },
                            error: function(err){
                                $.toast(err.message);
                            },
                            done: function(){
                                _this.isFetching = false;
                            }
                        });
                    }
                },
                mounted(){
					$.initJs(this);
                    setTimeout(function(){
                        document.querySelector(".nickInput").focus();
                    },0);
                }
            });

            api.addEventListener({name: 'settingsSaveNickName'}, function(ret, err){
                app.saveNickName();
            });
        }
    </script>
</body>
</html>
